package com.pet.server.ext.service;
import java.util.List;

import com.pet.server.ext.ApiError;
import com.pet.server.ext.data.AnswerInfo;
import com.pet.server.ext.dbutil.JdbcTemplate;
import com.pet.server.ext.dbutil.Sql;


public class RequestService {
	private JdbcTemplate jdbcTemplate = new JdbcTemplate();
	
	public boolean isSession(String sessionId) throws ApiError{
		Sql sql = new Sql("SELECT count(1) FROM answer_info aw WHERE aw.sessionid=?");
		sql.addParam(sessionId);
		return jdbcTemplate.findCount(sql)>0?true:false;
	}
	public List<AnswerInfo> queryAnswerInfobySessionId(String sessionId) throws ApiError{
		Sql sql = new Sql("SELECT a.*,u.ico_path,u.nick_name FROM answer_info a ,user_info u WHERE a.user_id=u.user_id AND a.sessionid=?");
		    sql.addParam(sessionId);
		    sql.append(" ORDER BY a.answer_id ASC");
		return jdbcTemplate.queryForList(sql, AnswerInfo.class);
	}
	
}
